import ViewBase from "../../engine/ViewBase";
import { SocketClient } from "../../net/SocketClient";
import { UserModel } from "../model/UserModel";
import { UIHelper } from "../util/UIHelper";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewUserInfoFixName extends ViewBase {

    private txtName: cc.EditBox

    onEnable(): void {
        super.onEnable()
        this.txtName = this.getChild(this.node, "txtName", cc.EditBox)
        this.txtName.string = UserModel.instance.userName;
        let btnOK: cc.Node = this.findChild(this.node, "btnOK")
        UIHelper.onAddEvent(btnOK, () => {

            if (this.txtName.string == "") {
                UIHelper.showTip("呢称不能为空")
                return
            }
            else if (this.txtName.string == UserModel.instance.userName) {
                UIHelper.showTip("呢称未修改哦")
                return
            }
            this.closeView()
            SocketClient.req_set_nick_name(this.txtName.string)
        })
    }

}
